$(document).ready(function($){
	
	$("#area-menu li").hover(function(){
		
		$(this).find("li").show();
		
	},function(){
		
		$(this).find("li").hide();
		
	});
	
	init_tol_tips();
	
});

function app_gen_alert(alert_est,alert_typ,alert_inf,alert_des){
	
	if(alert_est == true){
		
		$("#area-warn").show();
		
		switch(alert_typ){
			
			case 1:
				
				$("#ico-inf").show();
				$("#ico-spi").hide();
				$("#ico-war").hide();
				
				break;
				
			case 2:
				
				$("#ico-inf").hide();
				$("#ico-spi").show();
				$("#ico-war").hide();
				
				break;
				
			default:
				
				$("#ico-inf").hide();
				$("#ico-spi").hide();
				$("#ico-war").show();
								
				break;
				
		}
		
		$("#area-warn .cont-info").show().html(alert_inf);
		$("#area-warn .cont-desc").show().html(alert_des);
		//$("#area-warn .cont-help").show().html(alert_des);
		
	}else{
		console.log("desaparece");
		$("#area-warn").hide(function(){
			
			$("#ico-inf").hide();
			$("#ico-spi").hide();
			$("#ico-war").hide();
			
			$("#area-warn .cont-info").hide().empty();
			$("#area-warn .cont-desc").hide().empty();
			
		});
		//$("#area-warn .cont-help").show().empty();
		
	}
	
	
}

function pad(number, length) {
	   
	var str = '' + number;
    while (str.length < length) {
    	str = '0' + str;
    }
    		   
    return str;

}

function init_tol_tips(){
	
	$('td[estado="posi-disp-2"]').live("mouseover",function(){
		
		$(this).find('.trig-info').show();

	}).live("mouseout",function(){
		
		$(this).find('.trig-info').hide();

	}).live("mousemove",function(e){
		
		var mousex = e.pageX + 20;
		var mousey = e.pageY + 20;
		var tipWidth = $(this).find('.trig-info').width();
		var tipHeight = $(this).find('.trig-info').height();
		var tipVisX = $(window).width() - (mousex + tipWidth);
		var tipVisY = $(window).height() - (mousey + tipHeight);
		
		if(tipVisX < 20){			
			mousex = e.pageX - tipWidth - 20;			
		}if(tipVisY < 20){			
			mousey = e.pageY - tipHeight - 20;			
		} 
		
		$(this).find('.trig-info').css({
			top		:	mousey,
			left	:	mousex
		});
		
	});
	
	$('div[estado="posi-disp-2"]').live("mouseover",function(){
		
		$('#trig-info-' + $(this).attr("celda")).show();
		
	}).live("mouseout",function(){
		
		$('#trig-info-' + $(this).attr("celda")).hide();

	}).live("mousemove",function(e){
		
		var mousex = e.pageX + 20;
		var mousey = e.pageY + 20;
		var tipWidth = $('#trig-info-' + $(this).attr("celda")).width();
		var tipHeight = $('#trig-info-' + $(this).attr("celda")).height();
		var tipVisX = $(window).width() - (mousex + tipWidth);
		var tipVisY = $(window).height() - (mousey + tipHeight);
		
		if(tipVisX < 20){			
			mousex = e.pageX - tipWidth - 20;			
		}if(tipVisY < 20){			
			mousey = e.pageY - tipHeight - 20;			
		} 
		
		$('#trig-info-' + $(this).attr("celda")).css({
			top		:	mousey,
			left	:	mousex
		});
		
	});
	
	$('td[esta="posi-disp-2"]').live("mouseover",function(){
		
		$('#trig-info-' + $(this).attr("celda")).show();
		
	}).live("mouseout",function(){
		
		$('#trig-info-' + $(this).attr("celda")).hide();

	}).live("mousemove",function(e){
		
		var mousex = e.pageX + 20;
		var mousey = e.pageY + 20;
		var tipWidth = $('#trig-info-' + $(this).attr("celda")).width();
		var tipHeight = $('#trig-info-' + $(this).attr("celda")).height();
		var tipVisX = $(window).width() - (mousex + tipWidth);
		var tipVisY = $(window).height() - (mousey + tipHeight);
		
		if(tipVisX < 20){			
			mousex = e.pageX - tipWidth - 20;			
		}if(tipVisY < 20){			
			mousey = e.pageY - tipHeight - 20;			
		} 
		
		$('#trig-info-' + $(this).attr("celda")).css({
			top		:	mousey,
			left	:	mousex
		});
		
	});
	
		
}